VERSION 5.00
Object = "{76DA8CE9-E736-47FC-B43F-82650E2EFBAF}#1.0#0"; "oControls.ocx"
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
Begin VB.Form frmToolLogin 
   BackColor       =   &H00FFFFFF&
   BorderStyle     =   1  'Fixed Single
   Caption         =   "Logon"
   ClientHeight    =   3810
   ClientLeft      =   45
   ClientTop       =   375
   ClientWidth     =   5235
   Icon            =   "frmToolLogin.frx":0000
   LinkTopic       =   "Form1"
   LockControls    =   -1  'True
   MaxButton       =   0   'False
   MinButton       =   0   'False
   ScaleHeight     =   3810
   ScaleWidth      =   5235
   StartUpPosition =   2  'CenterScreen
   Begin VB.Timer Timer1 
      Interval        =   100
      Left            =   4635
      Top             =   1980
   End
   Begin MSComctlLib.ImageList imglist 
      Left            =   4500
      Top             =   2565
      _ExtentX        =   1005
      _ExtentY        =   1005
      BackColor       =   -2147483643
      ImageWidth      =   16
      ImageHeight     =   16
      MaskColor       =   12632256
      _Version        =   393216
      BeginProperty Images {2C247F25-8591-11D1-B16A-00C0F0283628} 
         NumListImages   =   2
         BeginProperty ListImage1 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmToolLogin.frx":0A02
            Key             =   ""
         EndProperty
         BeginProperty ListImage2 {2C247F27-8591-11D1-B16A-00C0F0283628} 
            Picture         =   "frmToolLogin.frx":1414
            Key             =   ""
         EndProperty
      EndProperty
   End
   Begin oControls.oCheckBox chkTop 
      Height          =   210
      Left            =   150
      TabIndex        =   9
      Top             =   3420
      Width           =   1395
      _ExtentX        =   2461
      _ExtentY        =   370
      BackColor       =   16777215
      ForeColor       =   8388608
      BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      Caption         =   "Always on Top"
      Value           =   1
   End
   Begin VB.PictureBox Picture1 
      AutoSize        =   -1  'True
      BorderStyle     =   0  'None
      Height          =   1380
      Left            =   0
      Picture         =   "frmToolLogin.frx":1E26
      ScaleHeight     =   1380
      ScaleWidth      =   5250
      TabIndex        =   17
      Top             =   0
      Width           =   5250
   End
   Begin oControls.oCommandButton btnOK 
      Height          =   285
      Left            =   1665
      TabIndex        =   4
      Top             =   3390
      Width           =   1095
      _ExtentX        =   1931
      _ExtentY        =   503
      BTYPE           =   3
      TX              =   "OK"
      ENAB            =   0   'False
      BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      COLTYPE         =   1
      FOCUSR          =   -1  'True
      BCOL            =   15790320
      BCOLO           =   15790320
      FCOL            =   0
      FCOLO           =   0
      MCOL            =   12632256
      MPTR            =   1
      MICON           =   "frmToolLogin.frx":76E2
      UMCOL           =   -1  'True
      SOFT            =   0   'False
      PICPOS          =   0
      NGREY           =   0   'False
      FX              =   0
      HAND            =   0   'False
      CHECK           =   0   'False
      VALUE           =   0   'False
   End
   Begin oControls.oCommandButton btnCancel 
      Height          =   285
      Left            =   2865
      TabIndex        =   5
      Top             =   3390
      Width           =   1095
      _ExtentX        =   1931
      _ExtentY        =   503
      BTYPE           =   3
      TX              =   "Cancel"
      ENAB            =   -1  'True
      BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      COLTYPE         =   1
      FOCUSR          =   -1  'True
      BCOL            =   15790320
      BCOLO           =   15790320
      FCOL            =   0
      FCOLO           =   0
      MCOL            =   12632256
      MPTR            =   1
      MICON           =   "frmToolLogin.frx":76FE
      UMCOL           =   -1  'True
      SOFT            =   0   'False
      PICPOS          =   0
      NGREY           =   0   'False
      FX              =   0
      HAND            =   0   'False
      CHECK           =   0   'False
      VALUE           =   0   'False
   End
   Begin oControls.oCommandButton btnOption 
      Height          =   285
      Left            =   4035
      TabIndex        =   6
      Top             =   3390
      Width           =   1095
      _ExtentX        =   1931
      _ExtentY        =   503
      BTYPE           =   3
      TX              =   "Option >>"
      ENAB            =   -1  'True
      BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      COLTYPE         =   1
      FOCUSR          =   -1  'True
      BCOL            =   15790320
      BCOLO           =   15790320
      FCOL            =   0
      FCOLO           =   0
      MCOL            =   12632256
      MPTR            =   1
      MICON           =   "frmToolLogin.frx":771A
      UMCOL           =   -1  'True
      SOFT            =   0   'False
      PICPOS          =   0
      NGREY           =   0   'False
      FX              =   0
      HAND            =   0   'False
      CHECK           =   0   'False
      VALUE           =   0   'False
   End
   Begin oControls.oTab oTab1 
      Height          =   1890
      Left            =   0
      TabIndex        =   7
      Top             =   1380
      Width           =   5235
      _ExtentX        =   9234
      _ExtentY        =   3334
      TabCount        =   2
      TabCaption(0)   =   "          Login          "
      TabContCtrlCnt(0)=   6
      Tab(0)ContCtrlCap(1)=   "txtcPassword"
      Tab(0)ContCtrlCap(2)=   "txtcUserID"
      Tab(0)ContCtrlCap(3)=   "cboCompanyID"
      Tab(0)ContCtrlCap(4)=   "cboRoleID"
      Tab(0)ContCtrlCap(5)=   "txtcCompanyID"
      Tab(0)ContCtrlCap(6)=   "txtcRoleID"
      TabCaption(1)   =   "         Option         "
      TabContCtrlCnt(1)=   6
      Tab(1)ContCtrlCap(1)=   "btnDefault"
      Tab(1)ContCtrlCap(2)=   "btnSave"
      Tab(1)ContCtrlCap(3)=   "txtPassword"
      Tab(1)ContCtrlCap(4)=   "txtDatabaseName"
      Tab(1)ContCtrlCap(5)=   "txtDataSourceName"
      Tab(1)ContCtrlCap(6)=   "txtServerName"
      TabStyle        =   1
      TabTheme        =   1
      ActiveTabBackStartColor=   16777215
      ActiveTabBackEndColor=   16777215
      InActiveTabBackStartColor=   16777215
      InActiveTabBackEndColor=   15397104
      BeginProperty ActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   700
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      BeginProperty InActiveTabFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
         Name            =   "Tahoma"
         Size            =   8.25
         Charset         =   0
         Weight          =   400
         Underline       =   0   'False
         Italic          =   0   'False
         Strikethrough   =   0   'False
      EndProperty
      OuterBorderColor=   10198161
      DisabledTabBackColor=   -2147483633
      DisabledTabForeColor=   10526880
      Begin oControls.oCommandButton btnDefault 
         Height          =   285
         Left            =   -70935
         TabIndex        =   15
         Top             =   510
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   503
         BTYPE           =   3
         TX              =   "Load Default"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmToolLogin.frx":7736
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
      Begin oControls.oCommandButton btnSave 
         Height          =   285
         Left            =   -70935
         TabIndex        =   16
         Top             =   810
         Width           =   1095
         _ExtentX        =   1931
         _ExtentY        =   503
         BTYPE           =   3
         TX              =   "Save"
         ENAB            =   -1  'True
         BeginProperty FONT {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         COLTYPE         =   1
         FOCUSR          =   -1  'True
         BCOL            =   15790320
         BCOLO           =   15790320
         FCOL            =   0
         FCOLO           =   0
         MCOL            =   12632256
         MPTR            =   1
         MICON           =   "frmToolLogin.frx":7752
         UMCOL           =   -1  'True
         SOFT            =   0   'False
         PICPOS          =   0
         NGREY           =   0   'False
         FX              =   0
         HAND            =   0   'False
         CHECK           =   0   'False
         VALUE           =   0   'False
      End
      Begin oControls.oTextBox txtPassword 
         Height          =   285
         Left            =   -74790
         TabIndex        =   14
         Top             =   1410
         Width           =   3765
         _ExtentX        =   6429
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Password"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2205
      End
      Begin oControls.oTextBox txtDatabaseName 
         Height          =   285
         Left            =   -74790
         TabIndex        =   13
         Top             =   1110
         Width           =   3765
         _ExtentX        =   6429
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Database Name"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2205
      End
      Begin oControls.oTextBox txtDataSourceName 
         Height          =   285
         Left            =   -74790
         TabIndex        =   12
         Top             =   810
         Width           =   3765
         _ExtentX        =   6429
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Data Source Name"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2205
      End
      Begin oControls.oTextBox txtServerName 
         Height          =   285
         Left            =   -74790
         TabIndex        =   11
         Top             =   510
         Width           =   3765
         _ExtentX        =   6429
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Server Name"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2205
      End
      Begin oControls.oTextBox txtcPassword 
         Height          =   285
         Left            =   255
         TabIndex        =   1
         Top             =   765
         Width           =   3885
         _ExtentX        =   6641
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Password"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2325
      End
      Begin oControls.oTextBox txtcUserID 
         Height          =   285
         Left            =   255
         TabIndex        =   0
         Top             =   465
         Width           =   3885
         _ExtentX        =   6641
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "User ID"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2325
      End
      Begin VB.ComboBox cboCompanyID 
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   1785
         Style           =   2  'Dropdown List
         TabIndex        =   2
         Top             =   1080
         Width           =   2370
      End
      Begin VB.ComboBox cboRoleID 
         BeginProperty Font 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Height          =   315
         Left            =   1785
         Style           =   2  'Dropdown List
         TabIndex        =   3
         Top             =   1455
         Width           =   2370
      End
      Begin oControls.oTextBox txtcCompanyID 
         Height          =   285
         Left            =   255
         TabIndex        =   8
         Top             =   1095
         Width           =   3885
         _ExtentX        =   6641
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Logon in"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2325
      End
      Begin oControls.oTextBox txtcRoleID 
         Height          =   285
         Left            =   255
         TabIndex        =   10
         Top             =   1425
         Width           =   3885
         _ExtentX        =   6641
         _ExtentY        =   503
         LabelBackColor  =   16777215
         BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         Label           =   "Login as"
         BeginProperty LabelFont {0BE35203-8F91-11CE-9DE3-00AA004BB851} 
            Name            =   "Tahoma"
            Size            =   8.25
            Charset         =   0
            Weight          =   400
            Underline       =   0   'False
            Italic          =   0   'False
            Strikethrough   =   0   'False
         EndProperty
         TextBoxWidth    =   2325
      End
   End
End
Attribute VB_Name = "frmToolLogin"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Private Declare Function GetUserName Lib "advapi32.dll" Alias "GetUserNameA" (ByVal lpBuffer As String, nSize As Long) As Long

Private Declare Function SetWindowPos Lib "user32" (ByVal hwnd As Long, ByVal hWndInsertAfter As Long, ByVal X As Long, ByVal Y As Long, ByVal cx As Long, ByVal cy As Long, ByVal wFlags As Long) As Long
    
Private Const SWP_NOMOVE = 2
Private Const SWP_NOSIZE = 1
Private Const FLAGS = SWP_NOMOVE Or SWP_NOSIZE
Private Const HWND_TOPMOST = -1
Private Const HWND_NOTOPMOST = -2

Private Sub btnCancel_Click()
    Unload Me
End Sub

Private Sub btnDefault_Click()
    txtServerName = "LOCALHOST"
    txtDataSourceName = "SQL SERVER"
    txtDatabaseName = "AZUL"
    txtPassword = ""
End Sub

Private Sub btnOK_Click()
    frmToolSplash.Show
    
    MiniERPMain.Show
    frmToolSplash.ZOrder
    
    Unload Me
End Sub

Private Sub btnOption_Click()
    If btnOption.Caption = "Option >>" Then
        btnOption.Caption = "<< Option"
        oTab1.Top = 1380
        chkTop.Top = 3420: btnOK.Top = 3330: btnCancel.Top = 3330: btnOption.Top = 3330
        Me.Height = 4275
        ReadConnection txtServerName, txtDataSourceName, txtDatabaseName, txtPassword
    Else
        btnOption.Caption = "Option >>"
        oTab1.Top = 1065
        chkTop.Top = 3050: btnOK.Top = 3000: btnCancel.Top = 3000: btnOption.Top = 3000
        Me.Height = 3930
        oTab1.ActiveTab = 0
    End If
End Sub

Private Sub btnSave_Click()
    Kill App.Path & "\Connection.ini"
    Open App.Path & "\Connection.ini" For Append As #1
    Write #1, "HOST = " & txtServerName
    Write #1, "DATASOURCE = " & txtDataSourceName
    Write #1, "DATABASE = " & txtDatabaseName
    Write #1, "PASSWORD = " & txtPassword
    Close #1
    SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
    MsgBox "Settings save!", vbInformation + vbOKOnly, ""
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub

Private Sub cboCompanyID_Click()
    sCompanyID = cboCompanyID
    PopulateCombo "cRoleID", "Sec_User_D", cboRoleID, "cUserID = '" & txtcUserID & "'"
    cboRoleID.SetFocus
End Sub

Private Sub cboCompanyID_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call cboCompanyID_Click
    ElseIf KeyAscii = 27 Then
        Call btnCancel_Click
    End If
End Sub

Private Sub cboRoleID_Click()
    sUserRole = cboRoleID
End Sub

Private Sub cboRoleID_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        Call cboRoleID_Click
        btnOK.SetFocus
    ElseIf KeyAscii = 27 Then
        Call btnCancel_Click
    End If
End Sub

Private Sub chkTop_Click()
    If chkTop.Value = Checked Then
        SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
    Else
        SetWindowPos Me.hwnd, HWND_NOTOPMOST, 0, 0, 0, 0, FLAGS
    End If
End Sub

Private Sub Form_Activate()
    SetWindowPos Me.hwnd, HWND_TOPMOST, 0, 0, 0, 0, FLAGS
End Sub

Private Sub Form_Load()
    oTab1.ActiveTab = 0
    oTab1.Top = 1065
    txtcUserID = UserNameLog
    chkTop.Value = Checked
    chkTop.Top = 3050: btnOK.Top = 3000: btnCancel.Top = 3000: btnOption.Top = 3000
    Me.Height = 3930
    
    ProjectVersion = "AZUL " & App.Major & "." & App.Minor & "." & App.Revision
    
End Sub


Function UserNameLog() As String
   Dim temp As String
   temp = String(100, Chr$(0))
   GetUserName temp, 100
   UserNameLog = UCase(Left$(temp, InStr(temp, Chr$(0)) - 1))
End Function

Private Sub Timer1_Timer()
    If sUserID <> "" And sUserRole <> "" And sCompanyID <> "" Then
        btnOK.Enabled = True
        Timer1.Enabled = False
    End If
End Sub

Private Sub txtcPassword_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        If SetConnection Then
            Me.Icon = imgList.ListImages(2).Picture
        Else
            Me.Icon = imgList.ListImages(1).Picture
        End If
        CheckLogin
    ElseIf KeyAscii = 27 Then
        Call btnCancel_Click
    End If
End Sub

Private Sub txtcUserID_KeyPress(KeyAscii As Integer)
    If KeyAscii = 13 Then
        txtcPassword.SetFocus
    ElseIf KeyAscii = 27 Then
        Call btnCancel_Click
    End If
End Sub

Public Function SetConnection() As Boolean
    ReadConnection frmToolLogin.txtServerName, frmToolLogin.txtDataSourceName, frmToolLogin.txtDatabaseName, frmToolLogin.txtPassword
    Set cn = New ADODB.Connection
    cn.CursorLocation = adUseClient
    cn.ConnectionString = sConnString
    cn.Open
    If cn.State = 1 Then SetConnection = True
End Function

Public Function CheckLogin() As Boolean
    If rs.State = 1 Then rs.Close
    rs.Open "select * from sec_user where cUserID = '" & txtcUserID & "'", cn, adOpenStatic, adLockReadOnly
    If UCase(rs!cPassword) = UCase(Decrypt(txtcPassword)) Then
        If rs!lInUse = True Then
            MsgBox "User currently logged in", vbInformation, ProjectVersion
            txtcUserID.SetFocus
        Else
            If rs!lLocked = True Then
                MsgBox "Account Locked." & Chr(13) & "Consult system administrator.", vbInformation, ProjectVersion
                txtcUserID.SetFocus
            Else
                sUserID = txtcUserID
                sUserName = GetValFrTable("cName", "Sec_User", "cUserID='" & txtcUserID & "'")
                
                PopulateCombo "cCompID", "Sec_CompanyAccess", cboCompanyID
                cboCompanyID.SetFocus
                CheckLogin = True
            End If
        End If
    Else
        If rs!lLocked = True Then
            MsgBox "Account Locked." & Chr(13) & "Consult system administrator.", vbInformation, ProjectVersion
            txtcUserID.SetFocus
        Else
            cn.Execute "UPDATE Sec_User SET nTry = nTry + 1 WHERE cUserID = '" & txtcUserID & "'"
            MsgBox "Invalid Password!", vbInformation, ProjectVersion
            txtcPassword.SetFocus
        End If
    End If
End Function

